'''
A basic Twisted web-client.

@author: Hatem Oraby
'''
#Python's urlOpener uses blocking sockets, other wise we would had
# used it.


from twisted.web import client, resource
from twisted.internet import reactor



def gotPage(string):
    print "Successfully got page:"
    print string
    
    
def failedGotPage(reason):
    print "Failed to get page."
    print "Reason: " + reason

if __name__ == "__main__":
    from sys import argv
    if len(argv) < 2:
        url = "http://127.0.0.1:8080"
        print "No URL specified. To specify URL:"
        print  argv[0] +  " http:\\addressOrIp:Port"
        print "Using default URL: " + url
    else:
        url = argv[1]

    d = client.getPage(url)
    d.addCallbacks(gotPage, failedGotPage)
    reactor.run()